<?php  
class clsList
{		 
	var $lng 		= 'vn' ;
	var $tw 		= 'All' ;
	var $pg 		= 1 ;
	var $city_id 	= 0 ;
	var $lm  		= '' ;
	var $start 		= 1 ;
	var $display 	= 10 ;
	var $paging 	= '' ;
	var $totalrow 	= 1000 ;
	var $sqlCount 	= ""  ;
	var $details_img 	= ""  ;
	var $SEO ;
	var $sql ;  
	var $main_url 	= "http://www.thiphan.com";
	var $lower 		= 'a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|đ|é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|í|ì|ỉ|ĩ|ị|ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|ý|ỳ|ỷ|ỹ|ỵ';
	var $upper 		= 'A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|Đ|É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ|Í|Ì|Ỉ|Ĩ|Ị|Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ|Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự|Ý|Ỳ|Ỷ|Ỹ|Ỵ';
	var $arrayUpper;
	var $arrayLower;
	
	function __construct ($pg='1', $tw='All', $totalrow=1000 )
	{ 
		$this->pg  			= $pg ;
		$this->tw  			= $tw ;
		$this->totalrow  	= $totalrow ; 
		$this->arrayUpper 	= explode('|',preg_replace("/\n|\t|\r/","",$this->upper));
		$this->arrayLower 	= explode('|',preg_replace("/\n|\t|\r/","",$this->lower));
		$this->mkSQL() ;
	}
	
	private function mkSQL()
	{
		$this->sql = "	SELECT *
						FROM _sanpham_cat_record
						WHERE 1 ";
		if($this->tw != 'All')
		{
			$this->sql .= " and id_tinh = ".$this->tw;		
		}
		$this->sql .= "	ORDER BY id DESC ";
		 
		//$this->start 	= ($this->pg - $this->start) * $this->display ;
		//$this->lm 		= " LIMIT ".$this->start.", ".$this->display ;
		//$this->sql 		.= $this->lm ; 
	}
	
	public static function Pagings( $totalrow,$curpage,$pageto,$maxrow=5,$maxpage=3 )
	{
		$paging = "";
		if($totalrow % $maxrow == 0) {
			$totalpage = (int)($totalrow/$maxrow);
		} else {
			$totalpage = (int)($totalrow /$maxrow)+ 1;
		}
		if($totalrow > $maxrow ){
			$start = 1;
			$end   = 1;
			$navi  = "" ;
			$list = "" ;
			for($i=0;$i<=$totalpage;$i++){
				if(($i > ((int)(($curpage - 1)/$maxpage))*$maxpage)&&($i <= ((int)(($curpage -1)/$maxpage + 1))*$maxpage)){
					if($start ==1 )$start = $i ;
					if($i == $curpage){
						$navi .= "  <a href='#' class='active'><span>".$i."</b></span></a>"; 
					}else {
						$navi .= " <a  href='".$pageto."".$i."'>".$i."</a><span>";
					}
					$end = $i ;
				}
			}
			//khai báo preview 
			if($curpage > $maxpage){
				$preview = " <a href='".$pageto."".($start - 1)."'> < </a>";
			}else{
				$preview = "" ;
			}
			// khai báo next 
			$i = ((int)(($curpage -1)/$maxpage + 1))*$maxpage;
			if($i < $totalpage){
				$next = " <a href='".$pageto."".($end + 1)."'> > </a>";
			} else {
				$next = "  " ;
			}
			$paging .= $list . $preview . $navi .$next ;
		}
		return $paging ;
	}
	
	private function mkPaging( $pageto  )
	{
		$this->mklink_pages(); 
		if( $this->totalrow >0 ) 
		{
			$maxpages = ( (int)( $this->totalrow / $this->display + 1 ) > 5? 5 : (int)( $this->totalrow / $this->display + 1 ) );
			$last = ( ($this->start + $this->display -1 ) >  $this->totalrow?  $this->totalrow: ($this->start + $this->display -1 ) );
			$this->paging = '<div class="PageNext">'.$this->Pagings($this->totalrow, $this->pg, $pageto, $this->display , $maxpages ) .'</div>';		
		}
		
	}
		
	private function mklink_pages()
	{ 
		$result = mysql_query($this->sqlCount);
		if( @mysql_num_rows($result) > 0)
		{
			$total = mysql_fetch_array($result);
			$this->totalrow = $total[0];
		}
	}
	 
	function count_list( $city_id  )
	{
		if(	$city_id != 'All'	){
			$sql 		= 	"SELECT count(*) FROM _sanpham_cat_record where id_tinh = ".$city_id." ";
		}else{
			$sql 		= 	"SELECT count(*) FROM _sanpham_cat_record";
		}		
		//$result 		= 	mysql_query($sql);
		//$data 			=	mysql_fetch_array($result);
		//$this->totalrow	=	$data[0]; 	
	}
	
	function get_day($time) 
	{
		$times 	= time();
		$day 	= 86400; 
		$dates = $times - ($day * $time);
		return date("Y-m-d", $dates );
	}
	
	function get_old_day($old,$time) 
	{
		$times 	= strtotime($old);
		$day 	= 86400; 
		$dates = $times + ($day * $time);
		return date("d-m-Y", $dates );
	}
	
	function orderby_category($url ='', $canmua ='', $time='', $city='', $price='',$catID='')
	{
		$canmuas 	= $canmua	!=''? '&canmua='.$canmua : '' ; 
		$citys 		= $city		!=''? '&city='.$city : '' ; 
		$times 		= $time		!=''? '&time='.$time : '' ; 
		$prices 	= $price	!=''? '&price='.$price : '' ; 
		$catIDs 	= $catID	!=''? '&catID='.$catID : '' ; 
		
		$location	=	'<div class="arraySearch">
							<p class="DropDown">Theo phạm vi</p>
							<ul>
							<li><a href="'.($url.$canmuas.$times.$prices.$catIDs).'">Tất cả</a></li>';
		$data = mysql_query("select * from _town_search where town_level =1 order by popular_index DESC limit 7");
		while($item = mysql_fetch_array($data))
		{
			if(	$item['town_id'] == $city  )
			{
				$location	.=	'<li><a href="'.($url.$canmuas.$times.'&town='.$item['town_id'].$prices.$catIDs).'" class="active">'.$item['name'].'</a></li>';
			}else{
				$location	.=	'<li><a href="'.($url.$canmuas.$times.'&town='.$item['town_id'].$prices.$catIDs).'">'.$item['name'].'</a></li>';
			}
		}
		
		$location	.=	'</ul>
						</div>';
		$type	=	'<div class="arraySearch">
							<p class="DropDown">Theo chuyên mục</p>
							<ul>
								<li><a '.($canmua ==1? ' class="active"': '').' href="'.($url.'&canmua=1'.$times.$citys.$prices.$catIDs).'">Cần bán</a></li>
								<li><a '.($canmua ==2? ' class="active"': '').' href="'.($url.'&canmua=2'.$times.$citys.$prices.$catIDs).'">Cần Mua</a></li>
								<li><a '.($canmua ==3? ' class="active"': '').' href="'.($url.'&canmua=3'.$times.$citys.$prices.$catIDs).'">Cho thuê</a></li>
								<li><a '.($canmua ==4? ' class="active"': '').' href="'.($url.'&canmua=4'.$times.$citys.$prices.$catIDs).'">Chuyển nhượng</a></li>
							</ul>
						</div>'; 
						
		$date	=	'<div class="arraySearch">
							<p class="DropDown">Theo thời gian</p>
							<ul>
								<li><a '.($time ==1? ' class="active"': '').'  href="'.($url.$canmuas.'&time=1'.$citys.$prices.$catIDs).'">Cách đây 1 ngày</a></li>
								<li><a '.($time ==3? ' class="active"': '').'  href="'.($url.$canmuas.'&time=3'.$citys.$prices.$catIDs).'">Cách đây 3 ngày</a></li>
								<li><a '.($time ==7? ' class="active"': '').'  href="'.($url.$canmuas.'&time=7'.$citys.$prices.$catIDs).'">Cách đây 7 ngày</a></li>
								<li><a '.($time ==15? ' class="active"': '').' href="'.($url.$canmuas.'&time=15'.$citys.$prices.$catIDs).'">Cách đây 15 ngày</a></li>
								<li><a '.($time ==30? ' class="active"': '').' href="'.($url.$canmuas.'&time=30'.$citys.$prices.$catIDs).'">Cách đây 30 ngày</a></li>
								<li><a '.($time ==''? ' class="active"': '').' href="'.($url.$canmuas.$citys.$prices.$catIDs).'">Tất cả</a></li>
							</ul>
						</div>'; 
		 
		$str		= '<div class="arraySearch">
							<p class="DropDown">Theo giá</p>
							<ul>
								<li><a '.($price ==1? ' class="active"': '').'  href="'.($url.$canmuas.$times.$citys.$catIDs.'&price=1').'">Dưới 300 000 đ</a></li>
								<li><a '.($price ==2? ' class="active"': '').'  href="'.($url.$canmuas.$times.$citys.$catIDs.'&price=2').'">Từ 300.000đ - 500.000đ</a></li>
								<li><a '.($price ==3? ' class="active"': '').'  href="'.($url.$canmuas.$times.$citys.$catIDs.'&price=3').'">Từ 500.000đ - 50.000.000đ</a></li>
								<li><a '.($price ==4? ' class="active"': '').'  href="'.($url.$canmuas.$times.$citys.$catIDs.'&price=4').'">Từ 50.00.000đ - 5000.000.000đ</a></li>
								<li><a '.($price ==5? ' class="active"': '').'  href="'.($url.$canmuas.$times.$citys.$catIDs.'&price=5').'">Từ 300.000đ - 500.000đ</a></li>
								<li><a '.($price ==''? ' class="active"': '').'  href="'.($url.$canmuas.$times.$citys.$catIDs).'" class="other">Khác</a></li>
							</ul>
						</div>';
		return $type.$date.$location.$str;
	}

	function getRecords( $canmua = 1, $city='', $thoigian='', $gia='' )
	{
		$m = ""; 
		$canmua = $canmua!= 1? 0 :1 ;
		$sql = "SELECT * FROM _sanpham_cat_record WHERE  published=1 and canban = ".$canmua ;
		$sqlcounts	=	"SELECT count(*) FROM _sanpham_cat_record WHERE  published=1 and canban = ".$canmua ;
		
		if($city != '' & $city != 'All'){		$sql .= " and id_tinh = ".$city;	$sqlcounts .= " and id_tinh = ".$city;	} 
		if($thoigian != ''){	$thoigian = $thoigian+1;  
								$sql .= " and date_start > '".$this->get_day($thoigian)."'";
								$sqlcounts .= " and date_start > '".$this->get_day($thoigian)."'";
		}
		if($gia != ''){			$sql .= " and id_gia = ".$gia;		$sqlcounts .= " and id_gia = ".$gia;		} 
		$sql .= " ORDER BY id DESC "; 
		$start 	= ($this->pg - $this->start) * $this->display ;
		$lm 		= " LIMIT ".$start.", ".$this->display ;
		$sql 		.= $lm ; 
		$result 		= 	mysql_query($sqlcounts);
		$data 			=	mysql_fetch_array($result);
		
		$this->totalrow	=	$data[0]; 
		// echo $sql;
		$result = mysql_query(	$sql	); 
		$company = array();
		$return = '';
		$total = @mysql_num_rows($result) ; 
		///////////////////
		//$strdo = new exec_String();		
		///////////////////
		if( $total > 0 )
		{
			$i=1;
			$stt = $this->start + 1 ;
			
			while($row = mysql_fetch_array($result))
			{
				
				$muaban =	 $row['canban'] ==1 ? 'can-ban':'can-mua' ;
				$url_name = $row['seo'].'.html';				
				$m = $this->main_url."/".$muaban.'-'.$url_name;
				$citys	= mysql_fetch_array(mysql_query("select * from _town_search where town_id=".$row['id_tinh']));
				$mem	= mysql_fetch_array(mysql_query("select * from _sanpham_members where memID=".$row['memid']));
																										 
				$return .= '<ul class="ProDuctsIteam">
								<li class="NameSP">
									<a href="'.$m.'"><img src="img/'.( $row['image']!=''? $row['image']: 'no-image.png').'" /></a>
									<a href="'.$m.'" class="linkProducts">'.$row['title'].'</a>
									<p>'.$row['alias'].'</p>
									<p class="noidang">
									<span class="ProdustsAddress">Khu vực: '.$citys['name'].'</span> - '.$row['add_date'].' Cách đây '.$this->show_time($row['date_start']).' - <span class="ProView">'.$row['view'].' xem</span></p>
								</li>
								<li class="NameCt">
									<p class="ProductsPrize">'.number_format($row['price'],0,'.','.').'VNĐ</p>
									<p class="NameShop">Thành Viên :  <a href="find.php?mem='.$mem['memID'].'">'.$mem['mLogin'].'</a></p>
									<p class="chatName"><a>Post: '.$mem['total'].'</a></p>
								</li>
							</ul>';
				$stt++;
				$i++;
			}
		} 
		$pageto	=	"find.php?"; 
		$pageto		.= $canmua	!=''? '&canmua='.$canmua : '' ; 
		$pageto 	.= $city	!=''? '&city='.$city : '' ; 
		$pageto 	.= $time	!=''? '&time='.$time : '' ; 
		$pageto 	.= $price	!=''? '&price='.$price : '' ;
		$pageto 	.="&page=";
		$this->mkPaging($pageto);
		$return = '<div class="block">'.$return.'</div>' ;
		
		return $return;
		
	}
	
	function loadMem( $mem ) 
	{
		if(!$mem)return ;
		$canmua = 	$canmua!= 1? 0 :1 ;
		$sql 	= 	"select * from _sanpham_members where memID=".$mem;
		$result	=	mysql_query($sql);
		$row 	= mysql_fetch_array($result);
		 
		$write	= mysql_fetch_array(mysql_query("select count(id) as total from _sanpham_cat_record where memid=".$mem));
		$return	=	"";
		$return = ' <div class="newsAD" id="newsAD"> 
						<div class="left">Thành viên:  <strong>'.$row['mLogin'].'</strong><br />Bài Post: <strong>'.$write[0].'</strong><br />Yahoo:<strong>'.$row['YM'].'</strong> - phone: <strong>'.$row['phone'].'</strong> - Email:<strong>'.$row['mEmail'].'</strong> - Địa chỉ: <strong>'.$row['address'].'</strong></div> 
						<a href="javascript:void(0);" class="right"><img width="14" height="14" border="0" src="images/close.jpg" onclick="javascript:document.getElementById(\'newsAD\').style.display=\'none\';"></a>
					</div>' ;
		
		return $return;
		
	}
	
	function getMem( $mem , $tw='', $catID='' ,$canmua=1, $time='', $price='' ) 
	{
		$m = ""; 
		$canmua = $canmua!= 1? 0 :1 ;
		$sql = "SELECT * FROM _sanpham_cat_record WHERE  published=1 and memid=".$mem;
		$sqlcounts	=	"SELECT count(*) FROM _sanpham_cat_record WHERE  published=1 and canban = ".$canmua ." and memid=".$mem; 
		
		if($city != '' & $city != 'All'){		$sql .= " and id_tinh = ".$city;	$sqlcounts .= " and id_tinh = ".$city;	} 
		if($thoigian != ''){	$thoigian = $thoigian+1;  
								$sql .= " and date_start > '".$this->get_day($thoigian)."'";
								$sqlcounts .= " and date_start > '".$this->get_day($thoigian)."'";
		}
		if($gia != ''){			$sql .= " and id_gia = ".$gia;		$sqlcounts .= " and id_gia = ".$gia;		} 
		$sql .= " ORDER BY id DESC "; 
		$start 	= ($this->pg - $this->start) * $this->display ;
		$lm 		= " LIMIT ".$start.", ".$this->display ;
		$sql 		.= $lm ; 
		$result 		= 	mysql_query($sqlcounts);
		$data 			=	mysql_fetch_array($result);
		
		$this->totalrow	=	$data[0]; 
		// echo $sql;
		$result = mysql_query(	$sql	); 
		$company = array();
		$return = '';
		$total = @mysql_num_rows($result) ; 
		///////////////////
		//$strdo = new exec_String();		
		///////////////////
		if( $total > 0 )
		{
			$i=1;
			$stt = $this->start + 1 ;
			
			while($row = mysql_fetch_array($result))
			{
				
				$muaban =	 $row['canban'] ==1 ? 'can-ban':'can-mua' ;
				$url_name =  $row['seo'].'.html';				
				$m = $this->main_url."/".$muaban.'-'.$url_name;
				$citys	= mysql_fetch_array(mysql_query("select * from _town_search where town_id=".$row['id_tinh']));
				$mem	= mysql_fetch_array(mysql_query("select * from _sanpham_members where memID=".$row['memid']));
																										 
				$return .= '<ul class="ProDuctsIteam">
								<li class="NameSP">
									<a href="'.$m.'"><img src="img/'.( $row['image']!=''? $row['image']: 'no-image.png').'" /></a>
									<a href="'.$m.'" class="linkProducts">'.$row['title'].'</a>
									<p>'.$row['alias'].'</p>
									<p class="noidang">
									<span class="ProdustsAddress">Khu vực: '.$citys['name'].'</span> - '.$row['add_date'].' Cách đây '.$this->show_time($row['date_start']).' - <span class="ProView">'.$row['view'].' xem</span></p>
								</li>
								<li class="NameCt">
									<p class="ProductsPrize">'.number_format($row['price'],0,'.','.').'VNĐ</p>
									<p class="NameShop">Thành Viên :  <a href="find.php?mem='.$mem['memID'].'">'.$mem['mLogin'].'</a></p>
									<p class="chatName"><a href="find.php?mem='.$mem['memID'].'">Post: '.$mem['total'].'</a></p>
								</li>
							</ul>';
				$stt++;
				$i++;
			}
		} 
		$pageto	=	"find.php?"; 
		$pageto		.= $mem		!=''? '&mem='.$mem : '' ; 
		$pageto		.= $canmua	!=''? '&canmua='.$canmua : '' ; 
		$pageto 	.= $city	!=''? '&city='.$city : '' ; 
		$pageto 	.= $time	!=''? '&time='.$time : '' ; 
		$pageto 	.= $price	!=''? '&price='.$price : '' ;
		$pageto 	.="&page=";
		$this->mkPaging($pageto);
		$return = '<div class="block">'.$return.'</div>' ;
		
		return $return;
		
	}
	
	function show_time($date) 
	{
		$time = time() - strtotime($date); // to get the time since that moment
	
		$tokens = array (
			31536000 => 'năm',
			2592000 => 'tháng',
			604800 => 'tuần',
			86400 => 'ngày',
			3600 => 'giờ',
			60 => 'phút',
			1 => 'giây'
		);
	
		foreach ($tokens as $unit => $text) {
			if ($time < $unit) continue;
			$numberOfUnits = floor($time / $unit);
			return $numberOfUnits.' '.$text;
		}
	}  

	function load_footer() 
	{
		$sql	=	"select * from _footer where published=1 "; 
		$sql	.=	" order by id DESC limit 16 ";
		$result = mysql_query(	$sql	);  
		$return = '';
		$total = @mysql_num_rows($result) ; 
		if( $total > 0 )
		{
			$i		=	1;
			while($row = mysql_fetch_array($result))
			{
				
			}
			return ' <div class="HotBuys">
						<div class="Title"><a>Tin post trong 24h qua </a></div>
						<div class="titleHotpost">
							<div class="cater">
								<select name="cbcate" id="cbcate">
									<option value="0">Tất cả danh mục</option>
									'.$cb.'
								</select>
							</div>
							<div class="left"><strong>Giá bán</strong></div>
						</div>
						<div class="clear"></div>
						<div class="HotList" id="listhost">
							<ul>'.$return.'</ul>
						</div>
					</div>';
		}
	}

	function getSearch( $keyword='',$catID ='' ,$thoigian='', $gia='', $pg = 0 , $city='All', $district='', $ward='', $street='' )
	{
		$condition 			= 	""; 
		$sql 		= 	"SELECT * FROM _sanpham_cat_record WHERE published=1 ";
		$sqlcounts	=	"SELECT count(*) FROM _sanpham_cat_record WHERE published=1 " ;
		
		if($keyword != ''){		$condition .= " and ( keyword like '%".$keyword."%' or title like '%".$keyword."%')"; 	}
		if($canmua != ''){		$condition .= " and canmua = ".( $canmua != 1? 0 : 1 ) ;	 }
		if($city != 'All'){		$condition .= " and id_tinh = ".$city;	}
		if($district != ''){	$condition .= " and id_quan = ".$district;	}
		if($ward != ''){		$condition .= " and id_huyen = ".$ward;	}
		if($street != ''){		$condition .= " and id_duong = ".$street;	}
		if($thoigian != ''){	$condition .= " and add_date > ".$this->get_day($thoigian);	$thoigian = $thoigian+1; 	}
		if($gia != ''){			$condition .= " and id_gia = ".$gia;	}
		if($catID!=''){			$condition .= " and parent =".$catID; 	}
		
		$condition 		.=  " ORDER BY id DESC ";
		
		$start 			= 	($pg - $this->start) * $this->display ;
		$lm 			= 	" LIMIT ".$start.", ".$this->display ;
		
		$result 		= 	mysql_query($sqlcounts.$condition);
		$data 			=	mysql_fetch_array($result);
		$this->totalrow	=	$data[0];
		
		$result 		= 	mysql_query(	$sql.$condition.$lm	); 
		$company 		= 	array();
		$return 		= 	'';
		$total 			= 	@mysql_num_rows($result) ;
		
		$keysearch 		=	$this->lower(
							$this->vn_str_filter(
								str_replace('Đ','d',									
										str_replace(' ','-',
											str_replace(' - ',' ',
												str_replace('&','-', 
													str_replace(' & ','-', 
														str_replace('/','-',
															str_replace(' / ','-',
																str_replace('.','',
																	str_replace(',',' ',
																		str_replace('(','-',
																			str_replace(' (','-',			 
																				 str_replace(')','-',
																					str_replace(' )','-',
																						   trim( $keyword ))))))))))))))))	;
			
		///////////////////
		//$strdo = new exec_String();
		///////////////////
		
		if( $total > 0 )
		{
			$i=1;
			$stt = $this->start + 1 ;
			
			while($row = mysql_fetch_array($result))
			{				
				$muaban =	 $row['canban'] ==1 ? 'can-ban':'can-mua' ;
				$url_name =  $row['seo'].'.html';				
				$m = $this->main_url."/".$muaban.'-'.$url_name;
				$city	= mysql_fetch_array(mysql_query("select * from _town_search where town_id=".$row['id_tinh']));
				$mem	= mysql_fetch_array(mysql_query("select * from _sanpham_members where memID=".$row['memid']));
																										 
				$return .= '<ul class="ProDuctsIteam">
								<li class="NameSP">
									<a href="'.$m.'"><img src="img/'.( $row['image']!=''? $row['image']: 'no-image.png').'" /></a>
									<a href="'.$m.'" class="linkProducts">'.$row['title'].'</a>
									<p>'.$row['alias'].'</p>
									<p class="noidang">
									<span class="ProdustsAddress">Khu vực: '.$city['name'].'</span> - '.$row['add_date'].' Cách đây '.$this->show_time($row['date_start']).' - <span class="ProView">'.$row['view'].' xem</span></p>
								</li>
								<li class="NameCt">
									<p class="ProductsPrize">'.number_format($row['price'],0,'.','.').'VNĐ VND</p>
									<p class="NameShop">Thành Viên :  <a href="find.php?mem='.$mem['memID'].'">'.$mem['mLogin'].'</a></p>
									<p class="chatName"><a>Post: '.$mem['total'].'</a></p>
								</li>
							</ul>';
				$stt++;
				$i++;
			}
		}
	
		$pageto	=	"find.php?keyword=".$keysearch; 
		$pageto		.= $canmua	!=''? '&canmua='.$canmua : '' ; 
		$pageto 	.= $city	!=''? '&city='.$city : '' ; 
		$pageto 	.= $time	!=''? '&time='.$time : '' ; 
		$pageto 	.= $price	!=''? '&price='.$price : '' ;
		$pageto 	.= $catID	!=''? '&catID='.$catID : '' ;
		$pageto 	.="&page=";
		$this->mkPaging($pageto);
		$return = '<div class="block">'.$return.'</div>' ;
		
		return $return;
		
	} 
	
	function getPartLink( $keyword='',$catID ='', $canmua ='', $city='', $thoigian='', $gia='' )
	{
		$return	=	"Home : "." > ".$catID;
		return $return;
	} 
	
	function getListCat( $keyword='',$catID ='', $canmua ='', $city='', $thoigian='', $gia='' ,$page='' )
	{
		$pageto	=	"find.php?";
		$pageto		.= $canmua	!=''? '&canmua='.$canmua : '' ; 
		$pageto 	.= $city	!=''? '&city='.$city : '' ; 
		$pageto 	.= $time	!=''? '&time='.$time : '' ; 
		$pageto 	.= $price	!=''? '&price='.$price : '' ;
		$pageto 	.= $page	!=''? '&page='.$page : '' ; 
		$return	=	"";
		if($catID!=''){
			$lookcat	= 	mysql_query("select * from _sanpham_cat where parent=".$catID);
			if(mysql_num_rows( $lookcat )>0)
			{
				$dot="";
				while($item	=	mysql_fetch_array($lookcat)){
					$return	.=	$dot."<a href='".$pageto."&catID=".$item['id']."'>".$item['title']."</a>";
					$dot 	=	" | ";
				}
				return '<div class="menuitem"> 
							<div class="left">'.$return.'</div>  
						</div>';
			} 
		}
		return $return;
	}
	
	function getCat( $catID='', $canmua ='', $city='', $thoigian='', $gia='' )
	{
		$m 			= 	""; 
		$sql 		= 	"SELECT * FROM _sanpham_cat_record WHERE published=1 ";
		$sqlcounts	=	"SELECT count(*) FROM _sanpham_cat_record WHERE published=1 "; 
		
		if($catID!=''){
			$Pon		=	$catID ;
			$lookcat	= 	mysql_query("select * from _sanpham_cat where parent=".$catID);
			if(mysql_num_rows( $lookcat )>0)
			{
				while($item	=	mysql_fetch_array($lookcat)){
					$Pon		.=	', '.$item[0];
				}
				$looksub		= 	mysql_query("select * from _sanpham_cat where parent in ( ".$Pon." ) ");
				if(mysql_num_rows( $looksub )>0)
				{
					while($items	=	mysql_fetch_array($looksub)){
						$Pon		.=	', '.$items[0];
					}
				}
			}
			$sql 		.= 	" and  parent in ( ".$Pon." )";
			$sqlcounts	.=	" and  parent in ( ".$Pon." )";
		}
		
		if($canmua != ''){		$sql .= " and canmua = ".( $canmua != 1? 0 : 1 );	$sqlcounts .= " and canmua = ".( $canmua != 1? 0 : 1 );	}
		if($city != '' & $city != 'All'){		$sql .= " and id_tinh = ".$city;	$sqlcounts .= " and id_tinh = ".$city;	} 
		if($thoigian != ''){	$thoigian = $thoigian+1;  
								$sql .= " and add_date > ".$this->get_day($thoigian);		$sqlcounts .= " and add_date > ".$this->get_day($thoigian);
		}
		if($gia != ''){			$sql .= " and id_gia = ".$gia;		$sqlcounts .= " and id_gia = ".$gia;		} 
		$sql .= " ORDER BY id DESC "; 
		$start 	= ($this->pg - $this->start) * $this->display ;
		$lm 		= " LIMIT ".$start.", ".$this->display ;
		$sql 		.= $lm ; 
		 
		$result 		= 	mysql_query($sqlcounts);
		$data 			=	mysql_fetch_array($result);
		$this->totalrow	=	$data[0];
		
		$result = mysql_query(	$sql	); 
		$company = array();
		$return = '';
		$total = @mysql_num_rows($result) ;
		
		$keysearch =	 $this->lower(
							$this->vn_str_filter(
								str_replace('Đ','d',
									
										str_replace(' ','-',
											str_replace(' - ',' ',
												str_replace('&','-', 
													str_replace(' & ','-', 
														str_replace('/','-',
															str_replace(' / ','-',
																str_replace('.','',
																	str_replace(',',' ',
																		str_replace('(','-',
																			str_replace(' (','-',			 
																				 str_replace(')','-',
																					str_replace(' )','-',
																						   trim( $keyword ))))))))))))))))	;		
		///////////////////
		//$strdo = new exec_String();
		///////////////////
		
		if( $total > 0 )
		{
			$i=1;
			$stt = $this->start + 1 ;
			
			while($row = mysql_fetch_array($result))
			{				
				$muaban =	 $row['canban'] ==1 ? 'can-ban':'can-mua' ;
				$url_name =  $row['seo'].'.html';				
				$m = $this->main_url."/".$muaban.'-'.$url_name;
				$city	= mysql_fetch_array(mysql_query("select * from _town_search where town_id=".$row['id_tinh']));
				$mem	= mysql_fetch_array(mysql_query("select * from _sanpham_members where memID=".$row['memid']));
																										 
				$return .= '<ul class="ProDuctsIteam">
								<li class="NameSP">
									<a href="'.$m.'"><img src="img/'.( $row['image']!=''? $row['image']: 'no-image.png').'" /></a>
									<a href="'.$m.'" class="linkProducts">'.$row['title'].'</a>
									<p>'.$row['alias'].'</p>
									<p class="noidang">
									<span class="ProdustsAddress">Khu vực: '.$city['name'].'</span> - '.$row['add_date'].' Cách đây '.$this->show_time($row['date_start']).' - <span class="ProView">'.$row['view'].' xem</span></p>
								</li>
								<li class="NameCt">
									<p class="ProductsPrize">'.number_format($row['price'],0,'.','.').'VNĐ</p>
									<p class="NameShop">Thành Viên :  <a href="find.php?mem='.$mem['memID'].'">'.$mem['mLogin'].'</a></p>
									<p class="chatName"><a>Post: '.$mem['total'].'</a></p>
								</li>
							</ul>';
				$stt++;
				$i++;
			}
		}
	
		$pageto	=	"find.php?keyword=".$keysearch;
		$pageto		.= $canmua	!=''? '&canmua='.$canmua : '' ; 
		$pageto 	.= $city	!=''? '&city='.$city : '' ; 
		$pageto 	.= $time	!=''? '&time='.$time : '' ; 
		$pageto 	.= $price	!=''? '&price='.$price : '' ;
		$pageto 	.="&page=";
		$this->mkPaging($pageto);
		$return = '<div class="block">'.$return.'</div>' ;
		
		return $return;
		
	}
	
	function getAll(  $city='', $catID='', $canmua ='', $thoigian='', $gia='' )
	{
		$m 			= 	""; 
		$sql 		= 	"SELECT * FROM _sanpham_cat_record WHERE published=1 ";
		$sqlcounts	=	"SELECT count(*) FROM _sanpham_cat_record WHERE published=1 "; 
		
		if($catID!=''){		$sql 		.= 	" and parent =".$catID;		$sqlcounts	.=	" and parent =".$catID;	}		
		// if($canmua != ''){		$sql .= " and canmua = ".( $canmua != 1? 0 : 1 );	$sqlcounts .= " and canmua = ".( $canmua != 1? 0 : 1 );	}
		if($city != '' & $city != 'All'){		$sql .= " and id_tinh = ".$city;	$sqlcounts .= " and id_tinh = ".$city;	} 
		if($thoigian != ''){	$thoigian = $thoigian+1;  
								$sql .= " and add_date > ".$this->get_day($thoigian);		$sqlcounts .= " and add_date > ".$this->get_day($thoigian);
		}
		if($gia != ''){			$sql .= " and id_gia = ".$gia;		$sqlcounts .= " and id_gia = ".$gia;		}
		
		$sql .= " ORDER BY id DESC "; 
		$start 	= ($this->pg - $this->start) * $this->display ;
		$lm 		= " LIMIT ".$start.", ".$this->display ;
		$sql 		.= $lm ; 
		 
		$result 		= 	mysql_query($sqlcounts);
		$data 			=	mysql_fetch_array($result);
		$this->totalrow	=	$data[0];
		
		$result = mysql_query(	$sql	); 
		$company = array();
		$return = '';
		$total = @mysql_num_rows($result) ;
		
		$keysearch =	 $this->lower(
							$this->vn_str_filter(
								str_replace('Đ','d',
									
										str_replace(' ','-',
											str_replace(' - ',' ',
												str_replace('&','-', 
													str_replace(' & ','-', 
														str_replace('/','-',
															str_replace(' / ','-',
																str_replace('.','',
																	str_replace(',',' ',
																		str_replace('(','-',
																			str_replace(' (','-',			 
																				 str_replace(')','-',
																					str_replace(' )','-',
																						   trim( $keyword ))))))))))))))))	;		
		///////////////////
		//$strdo = new exec_String();
		///////////////////
		
		if( $total > 0 )
		{
			$i=1;
			$stt = $this->start + 1 ;
			
			while($row = mysql_fetch_array($result))
			{				
				$muaban =	 $row['canban'] ==1 ? 'can-ban':'can-mua' ;
				$url_name =  $row['seo'].'.html';				
				$m = $this->main_url."/".$muaban.'-'.$url_name;
				$city	= mysql_fetch_array(mysql_query("select * from _town_search where town_id=".$row['id_tinh']));
				$mem	= mysql_fetch_array(mysql_query("select * from _sanpham_members where memID=".$row['memid']));
																										 
				$return .= '<ul class="ProDuctsIteam">
								<li class="NameSP">
									<a href="'.$m.'"><img src="img/'.( $row['image']!=''? $row['image']: 'no-image.png').'" /></a>
									<a href="'.$m.'" class="linkProducts">'.$row['title'].'</a>
									<p>'.$row['alias'].'</p>
									<p class="noidang">
									<span class="ProdustsAddress">Khu vực: '.$city['name'].'</span> - '.$row['add_date'].' Cách đây '.$this->show_time($row['date_start']).' - <span class="ProView">'.$row['view'].' xem</span></p>
								</li>
								<li class="NameCt">
									<p class="ProductsPrize">'.number_format($row['price'],0,'.','.').'VNĐ VND</p>
									<p class="NameShop">Thành Viên :  <a href="find.php?mem='.$mem['memID'].'">'.$mem['mLogin'].'</a></p>
									<p class="chatName"><a>Post: '.$mem['total'].'</a></p>
								</li>
							</ul>';
				$stt++;
				$i++;
			}
		}
	
		$pageto	=	"partner.php?";
		$pageto		.= $canmua	!=''? '&canmua='.$canmua : '' ; 
		$pageto 	.= $city	!=''? '&city='.$city : '' ; 
		$pageto 	.= $time	!=''? '&time='.$time : '' ; 
		$pageto 	.= $price	!=''? '&price='.$price : '' ;
		$pageto 	.="&page=";
		$this->mkPaging($pageto);
		$return = '<div class="block">'.$return.'</div>' ;
		
		return $return;
		
	}
	
	function getTown($url='' )
	{
		$sql		=	"select * from _town_search where 	town_sub=0 and town_level =1	" ;
		$result 	= 	mysql_query(	$sql	); 
		$company 	= 	array();
		$return 	= 	'';
		$total 		= 	@mysql_num_rows($result) ;
		
		///////////////////
		//$strdo = new exec_String();
		///////////////////
		
		if( $total > 0 )
		{
			$i=1;
			$stt = $this->start + 1 ;
			$return .= '<table width="100%">
						<tbody>
						<tr>';
			while($row = mysql_fetch_array($result))
			{
				$return .= '<td width="30" style="color:gray">'.$row['townlink'].'</td>
							<td style="font-weight:bold"><a href="'.$url.'&town='.$row['town_id'].'">'.$row['name'].'</a></td>';
				if($i==3){ 
					$return .= '</tr><tr>';
					$i=1;
				}else{
					$i++;
				}
			}
			$return .= '</tr>
					</tbody>
				</table>';
		}  
		return $return;
		
	}
	
	function getDetails( $seo )
	{ 
		$sql = "SELECT * FROM _sanpham_cat_record WHERE seo like '%".$seo."%' and published=1" ;  
		$result = mysql_query(	$sql	); 
		$return = '';
		$total = @mysql_num_rows($result) ; 
		///////////////////
		//$strdo = new exec_String();		
		/////////////////// 
		if( $total > 0 )
		{
			$row 		=	mysql_fetch_array($result);  
			mysql_query("update _sanpham_cat_record set view='".($row['view']+1)."' where id=".$row['id']);
			$this->details_img =	( $row['image']!=''? $row['image']: 'no-image.png');
			$m 			= 	$this->main_url."/".$muaban.'-'.$url_name;
			@$member 	=	mysql_fetch_array( mysql_query( "select * from _sanpham_members where memID=".$row['memid'] )); 
			@$datakhac	= 	mysql_query("SELECT * FROM _sanpham_cat_record WHERE memid =".$row['memid']." and published=1 limit 3 order by id DESC" ); 
			$other		=	""; 
			if(mysql_num_rows($datakhac)>0)
			{
				while( $items =  mysql_fetch_array($datakhac) )
				{
					$muaban =	 $items['canban'] ==1 ? 'can-ban':'can-mua' ;
					$url_name =  $items['seo'].'.html';				
					$m = $this->main_url."/".$muaban.'-'.$url_name;
				
					$other		.= '<div class="NewsProducts">
										<a href="'.$m.'"><img src="img/'.$items['image'].'" width="60" height="60" border="0"/></a>
										<a class="" href="'.$m.'">'.$items['title'].'</a>
										<p>'.$items['alias'].'</p>
										<div style="clear:both"></div>
									</div>';
				}
			}
			$tinh = mysql_fetch_array(mysql_query("select * from _town_search where town_id=".$row['id_tinh']));
			
			$return .= '<div class="BDcontent">
							<div class="TitleSearch"><a href="index.php">Trang Chủ</a> <a>'.$row['title'].'</a> </div> 
							<input type="hidden" name="id" id="id" value="'.$row['id'].'" />
							<input type="hidden" name="memid" id="memid" value="'.( isset($_SESSION['ses_login'])? $_SESSION['ses_login']['s_user']:'').'" />
							<div class="DetailProducts">  
								<div class="ImagDetail">
									<img src="img/'.( $row['image']!=''? $row['image']: 'no-image.png').'" name="image1" width="260" height="260" border="0" id="image1" />
								</div>
								<div class="InforProduct">
									<p class="nameDetail">'.$row['alias'].' </p>
									<table border="0" cellpadding="0" cellspacing="0">
									  <tr>
										<td width="108" height="25" valign="middle" align="right" class="tdleft">Giá hiện tại:</td>
										<td width="316" valign="middle"><span class="PrizeOK">'.number_format($row['price'],0,'.','.').'VNĐ</span></td>
									  </tr>
									   <tr>
										<td width="108" height="25" valign="middle" align="right" class="tdleft">Vị trí:</td>
										<td width="316" valign="middle" class="FreeShopTD">'.$tinh['name'].'</td>
									  </tr>
									  <tr>
										<td width="108" height="25" valign="middle" align="right" class="tdleft">Ngày đăng:</td>
										<td width="316" valign="middle">'.$row['date_start'].' - Cách đây :  <span class="Update">'.$this->show_time($row['date_start']).'</span> -   Ngày KT: '.$this->get_old_day($row['date_start'],($row['long_times']+1) ).' </td>
									  </tr> 
									   <tr>
										<td width="108" height="25" valign="middle" align="right" class="tdleft">bookmark : </td>
										<td width="316" valign="middle">
										'.( isset($_SESSION['ses_login'])?'<a href="#" name="bookmark" id="bookmark" >Lưu trang này</a>':'<a href="login.php">Lưu trang này</a>').' - lượt xem : '.$row['view'].'
											
										</td>
									  </tr> 
									  <tr>
										<td width="108" height="25" valign="middle" align="right" class="tdleft"></td>
										<td width="316" valign="middle">
											<input type="button" name="buy" id="buy" class="button" value="Mua Hàng" onclick="javascript:location.href=\'checkout.php?mode=add&id='.$row['id'].'\'"  />
											<input type="button" name="buyother" class="button" id="buyother" value="Mua Thêm" onclick="javascript:location.href=\'index.php\'" />  </td>
									  </tr>
									</table>
									<div class="YahooFone">
										<p class="TitleUser"><a class="nameUser" href="find.php?mem='.$member['memID'].'"> '.$member['mLogin'].'</a></p>
										<p><a href="ymsgr:sendim?'.$member['YM'].'"><img src="images/chatyahoo-icon.jpg" width="106" height="20" border="0" /></a></p>
										<p class="Phoneicon">Phone: <span class="PhoneUser"> '.$member['phone'].'</span></p>
										<p>Address: <span class="AddRess"> '.$member['address'].'.</span></p>
										<p>Email:<a class="linkweb" href="'.$member['email'].'"> '.$member['email'].'</a></p> 
										<p>Website:<a class="linkweb" href="javascript:mailto:'.$member['web'].'">'.$member['web'].'</a></p> 
									</div>
								</div>
								
							</div>
							<div class="clear"></div>
							<div class="detailInfo">
								<div class="leftDetail">
									<div class="ProducsTitle">
										<ul id="countrytabs" class="shadetabs">
											<li><a href="#" rel="#default" class="selected">Chi tiết sản phẩm</a></li> 
										</ul>
									</div><div class="clear"></div>
									<div id="countrydivcontainer" class="ContentTabDetail">
											'.$row['details'].'
									</div>
								</div>
								<div class="ReightProducts">
									<div class="PaneWhite">
										<div class="PaneWhiteTitle">Sản phẩm liên quan</div>
										<div class="PaneWhiteBody">
											 '.$other.'
										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="clear"></div>'; 
		}  
		$return = '<div class="block">'.$return.'</div>' ; 
		return $return;
	}
	
	function getfooters()
	{
		$m = "";
		$n = "";
		$result = mysql_query( "SELECT * FROM _sanpham_cat_record where published=1 ORDER BY id DESC limit 12 " ); 
		$return = '';
		$total = @mysql_num_rows($result);
		if( $total > 0 )
		{
			$muaban =	 $row['canban'] ==1 ? 'can-ban':'can-mua' ;
			$i=1;
			$stt = $this->start + 1 ;
			while($row = mysql_fetch_array($result))
			{
				$url_name =  $row['seo'] .'.html';				
				$m = $this->main_url.'/'.$muaban.'-'.$url_name;				
				$return .= '<li class="Slider" style="width:110px;">
								<a href="'.$m.'">
								<img src="img/'.( ( $row['image']!=''? $row['image']: 'no-image.png')!=''? ( $row['image']!=''? $row['image']: 'no-image.png'): 'no-image.png').'" width="75" height="75"  />
								<p>'.$row['title'].'</p>
								'.number_format($row['price'],0,'.','.').'VNĐ$</a><span>RPG 350 /Model 150</span>
							</li>';
				$stt++;
				$i++;
			}		
		}
		$return = '<div id="wrap">
					<ul id="mycarousel" class="jcarousel-skin-tango">
					'.$return.'
					</ul>
				</div>';
		return $return;
	}
	
	function lower( $str )
	{
		return str_replace($this->arrayUpper,$this->arrayLower,$str);
	}
		
	function upper( $str )
	{
		return str_replace($this->arrayLower,$this->arrayUpper,$str);
	}
	
	function vn_str_filter( $str)
	{  
		$unicode = array(  
			'a'=>'á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ',  
			'd'=>'đ',  
			'e'=>'é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ',  
			'i'=>'í|ì|ỉ|ĩ|ị',  
			'o'=>'ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ',  
			'u'=>'ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự',  
			'y'=>'ý|ỳ|ỷ|ỹ|ỵ',  
			'A'=>'Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ',  
			'D'=>'Đ',  
			'E'=>'É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ',  
			'I'=>'Í|Ì|Ỉ|Ĩ|Ị',  
			'O'=>'Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ',  
			'U'=>'Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự',  
			'Y'=>'Ý|Ỳ|Ỷ|Ỹ|Ỵ',  
		);  
		  
	   foreach($unicode as $nonUnicode=>$uni){  
			$str = preg_replace("/($uni)/i", $nonUnicode, $str);  
	   }  
		return $str;  
	} 
	
	function get_link( $keyword='', $catID ='', $city='' )
	{
		$data 		=	"";
		$pageto		=	'find.php?';
		$keywords	=	"";		
		$linkCat	=	'';
		if($keyword !=''){
			 $keywords	=	'&keyword='.$keyword;
			 $keyword	=	'('. $keyword.')';
		}
		if($city !=''){
			 $city  =	'&city='.$city ; 
		} 
		if($catID !=''){
			$result 	= 	mysql_query("select * from _sanpham_cat where id=".$catID);
			$data 		=	mysql_fetch_array($result);  
			if($data['parent']!='0'){
				$result 	= 	mysql_query("select * from _sanpham_cat where id=".$data['parent']);
				$item 		=	mysql_fetch_array($result);
				$catID		=	'&catID='.$item['id'];
				$linkCat	=	'<a href="'.$pageto.$keywords.$catID.$city.'">'.$item['title'].'</a>';
			}
			$catID		=	'&catID='.$data['id'];
			$linkCat	.=	'<a href="'.$pageto.$keywords.$catID.$city.'">'.$data['title'].'</a>';
		}
		return '<div class="TitleSearch">
					<a href="index.php">Trang chủ </a> <span>'. $keyword.'</span> '.$linkCat.'
				</div>';	
	}
	
}

?>